package org.light.domain;

import java.util.Iterator;
import java.util.Set;

import org.light.exception.ValidateException;
import org.light.utils.DomainUtil;
import org.light.utils.StringUtil;

public class DummyServiceImpl extends ServiceImpl {
	protected Domain domain;
	public DummyServiceImpl(){
		super();
	}	
	
	public DummyServiceImpl(Domain domain){
		super();
		this.domain = domain;
	}

	public String generateServiceImplString() throws ValidateException{
		StringBuilder sb = new StringBuilder();
		if (this.packageToken !=null && !"".equalsIgnoreCase(this.packageToken)) sb.append("package ").append(this.packageToken).append("."+this.domain.getServiceimplSuffix()+";\n\n");
		Set<String> imports = this.generateImportStrings();
		imports.addAll(this.classImports);
		
		for (String s: imports){
			sb.append("import ").append(s).append(";\n");
		}
		sb.append("\n");
		
		sb.append("public class ").append(StringUtil.capFirst(this.getDomain().getStandardName())).append("ServiceImpl implements ").append(StringUtil.capFirst(this.getDomain().getStandardName())).append("Service").append("{\n");
		sb.append("\tprotected ").append(StringUtil.capFirst(this.getDomain().getStandardName())).append("Dao dao = new ").append(StringUtil.capFirst(this.getDomain().getStandardName())).append("DummyDaoImpl();\n");

		for (Service service:this.otherServices){
			sb.append("\tprotected ").append(service.getStandardName()).append(" ").append(StringUtil.lowerFirst(service.getStandardName())).append(" = new ").append(service.getStandardName()).append("Impl();\n");
		}
		
		if (this.domain.containsImage()) {
    		sb.append("\tpublic static ").append(this.getDomain().getCapFirstDomainNameWithSuffix()).append("  temp"+this.domain.getCapFirstDomainName()+" = new ").append(this.getDomain().getCapFirstDomainNameWithSuffix()).append("();\n");		
		}

		Iterator it2 = this.methods.iterator();
		while(it2.hasNext()){
			Method m = (Method)it2.next();
			sb.append(m.generateMethodString()).append("\n");
		}
		sb.append("}\n");
		return sb.toString();
	}


	public Domain getDomain() {
		return domain;
	}


	public void setDomain(Domain domain) {
		this.domain = domain;
	}
	
	public ValidateInfo validate(){
		ValidateInfo info = new ValidateInfo();
		info.setSuccess(true);
		return info;
	}

}
